<?php
/**
 * 创作模块
 *
 * 创作模块service层
 *
 * @author    zhouchao <zhouchao@yunys.com.cn>
 * @copyright 2016 QuanZhouYunYiShang Inc.
 */
namespace App\Services\ProductsService;
use App\Services\ProductTempService\ProductTempTool;
use App\Services\Tool\ImageProcessor\Imagick;
use App\Services\Exceptions\ImageNotFoundException;
use App\Services\Exceptions\FontNotFoundException;
use App\Services\ImgServices\ImgTool;
use App\Services\SourcePicService\SourcePicTool;
use App\Services\Tool\Svg\SVGFont;
use App\Services\Tool\ImageProcessor\ImagickTool;
use App\Services\Tool\GeneralTool;
use DB;
use Log;

class ProductsCreateService
{
    const PREFIX_PATH = '/images/';
    const IMAGE_TEMPORARY_STORAGE_PATH = 'product_temporary_storage_images/';
    const IMAGE_PATH = 'product_images/';
    const COMPRESSION_QUALITY = 100;
    private $bg_color = '#E0E0E6';
    private $user_id = 0;
    private $product_temp_id;
    private $colour_id;
    private $position_type;
    private $app_version;
    public function __construct(ProductTempTool $product_temp_tool,SourcePicTool $source_pic_tool,ImagickTool $imagickTool)
    {
        $this->product_temp_tool = $product_temp_tool;
        $this->source_pic_tool = $source_pic_tool;
        $this->image_tool = $imagickTool;
    }

    /**
     * 生成预览图(衣服 新版)
     */
    public function create_product_preview($input)
    {
        set_time_limit(60);
        try{
            // Log::info('--数据--');
            // Log::info($input);
            //获取比例因子
            $this->app_version = isset($input['app_version']) && !empty($input['app_version']) ? $input['app_version'] : '';
            $this->user_id = $input['user_id'];
            $multiple = env('PREVIEW_HEIGHT')/$input['sketchpad_height']; //10 框
            $color_transparent = new \ImagickPixel('transparent'); //transparent 透明色
            // $color_transparent = new \ImagickPixel('#0000ff'); //transparent 透明色
            //获取
            foreach($input['product_templates'] as $product_template){
                //单个模板
                if(empty($product_template->creative_parameters)){
                    return array('message'=>'您还有一款模板未有任何设计','result'=>(object)array(),'state'=>'M08018');
                }
                $least_one_create = false;
                foreach($product_template->creative_parameters as $creative_parameter){
                    $style_box_h = $creative_parameter->style_box_h*$multiple;//九宫格的高度
                    $style_box_w = $creative_parameter->style_box_w*$multiple;//九宫格的宽度
                    if(!empty($creative_parameter->image_parameters)){
                        $least_one_create = true;
                        //获取模板缩略图
                        $product_temp_thumbnail = $this->product_temp_tool->getProdTempCustomThumbnail($product_template->product_temp_id,intval($product_template->colour_id),$creative_parameter->position_type);
                        if(empty($product_temp_thumbnail) || !is_file(public_path('images/').$product_temp_thumbnail)){
                            throw new \Exception('ID为'.$product_template->product_temp_id.',颜色ID为'.$product_template->colour_id.',position_type为'.$creative_parameter->position_type.'的产品模板图片没有找到');
                            //return array('message'=>'产品的模板不存在','result'=>(object)array(),'state'=>'M08010');
                        }
                        $product_temp_thumbnail = public_path('images/').$product_temp_thumbnail;
                        $this->product_temp_id = $product_template->product_temp_id;
                        $this->colour_id = $product_template->colour_id;
                        $this->position_type = $creative_parameter->position_type;
                        $image_bg = $this->generates_background_image($product_temp_thumbnail);
                        //生产九宫格图片
                        $image_style_box = $this->generate_as_quares_grid_image($creative_parameter->image_parameters,$style_box_w,$style_box_h,$multiple,$color_transparent);

                        if(is_array($image_style_box) && isset($image_style_box['state'])){
                            return $image_style_box;
                        }
                        $image_bg->addWatermarkFromImage($image_style_box,$image_bg->getImageWidth()/2-$image_style_box->getImageWidth()/2,$image_bg->getImageHeight()/2-$image_style_box->getImageHeight()/2);

                        $image_path = $this->getImageName($image_bg);
                        $image_style_box->destory();
                        $image_bg->destory();
                        $creative_parameter->image_path = $image_path;
                    }
                }
                if(!$least_one_create){
                    return array('message'=>'您还有一款模板未有任何设计','result'=>(object)array(),'state'=>'M08018');
                }
            }
            return array('message'=>'成功','result'=>$input,'state'=>'M00000');
        }catch (\Exception $e){
            Log::info($e);
            Log::info('-------创建失败参数begin---------');
            Log::info($input);
            Log::info('-------创建失败参数end---------');
            return array('message'=>'制作失败，请重新尝试','result'=>(object)array(),'state'=>'M08016');
        }
    }

//    private function RGBtoCMYK($image_style_box, $icc_cmyk, $icc_rgb){
//        //$img_object = new Imagick($source);
//        if ($image_style_box->getImagick()->getImageColorspace() == 1 OR $image_style_box->getImagick()->getImageColorspace() == 13) {
//            $profiles = $image_style_box->getImagick()->getImageProfiles('*', false);
//            $has_icc_profile = (array_search('icc', $profiles) !== false);
//            if ($has_icc_profile === false) {
//                //$icc_cmyk = file_get_contents('./Public/Img/AdobeRGB1998.icc');
//                $image_style_box->getImagick()->profileImage('icc', $icc_cmyk);
//                unset($icc_cmyk);
//            }
//            //$icc_rgb = file_get_contents('./Public/Img/USWebUncoated.icc');
//            $image_style_box->getImagick()->profileImage('icc', $icc_rgb);
//            unset($icc_rgb);
//        }
//        $image_data = $image_style_box->getImagick()->getImageGeometry();
//        $image_style_box->getImagick()->setImageColorspace(12);
//        return $image_style_box;
//    }

    /**
     * 生产背景图片
     * @param $product_id
     * @param $colour_id
     * @param $sketchpadH
     * @param array $color
     * @return $this|Imagick
     */
    private function generates_background_image($product_temp_thumbnail)
    {
        //获取模板背景颜色
        $bg_color = $this->product_temp_tool->customZoneBackgroundColourCode($this->product_temp_id,intval($this->colour_id),$this->position_type);
        if($bg_color != ''){
            $this->bg_color = $bg_color;
        }
        $color = $this->hex2rgb($this->bg_color);
        $image_bg = new Imagick($product_temp_thumbnail);
        $image_width = $image_bg->getImageWidth()*(env('PREVIEW_HEIGHT')/$image_bg->getImageHeight());
        $image_bg = $image_bg->resize($image_width,env('PREVIEW_HEIGHT'),'scale_fill',$color);
        return $image_bg;
    }



    /**
     * 获取图片的名字
     * 保存在临时文件夹IMAGE_TEMPORARY_STORAGE_PATH
     */
    public function getImageName($image_bg)
    {
//        $icc_cmyk = file_get_contents(public_path('AdobeRGB1998.icc'));
//        $icc_rgb = file_get_contents(public_path('USWebUncoated.icc'));
//        $image_bg = $this->RGBtoCMYK($image_bg,$icc_cmyk,$icc_rgb);
        $image_bg->setType('JPEG');
        $compression_type = \Imagick::COMPRESSION_JPEG;
        $image_bg->getImagick()->setImageCompression($compression_type);
        $image_bg->getImagick()->setImageCompressionQuality(self::COMPRESSION_QUALITY);
        $image_bg->stripImage();
        $extension = '.jpg';
        $prefix_name = md5(date('ymdhis').rand(1, 1000));
        $child_folder = date('Ym',time());
//        $folder = public_path() .self::PREFIX_PATH.self::IMAGE_PATH.$child_folder;
        $folder = public_path() .self::PREFIX_PATH.self::IMAGE_TEMPORARY_STORAGE_PATH.$child_folder;
        @$this->mkFolder($folder);
        $folder_path=$folder.'/'.$prefix_name.$extension;
        $flag = $image_bg->saveTo($folder_path);
        if($flag != true){
            throw new \Exception('图片保存失败');
        }
        $real_path = self::IMAGE_TEMPORARY_STORAGE_PATH.$child_folder.'/'.$prefix_name.$extension;
        return $real_path;
    }

    /**
     * 生成九宫格图片
     */
    private function generate_as_quares_grid_image($image_parameters,$style_box_w,$style_box_h,$multiple,$color_transparent)
    {
        $image_style_box = new Imagick();
        $image_style_box = $image_style_box->newImage($style_box_w,$style_box_h,$color_transparent,'png');
        $image_make_picture = new Imagick();
        //排序
        usort($image_parameters, function($a, $b) {
            $al = $a->edit_view_level;
            $bl = $b->edit_view_level;
            if ($al == $bl)
                return 0;
            return ($al > $bl) ? 1 : -1;
        });
        foreach($image_parameters as $image){
            if(empty($this->app_version) || GeneralTool::compare_versions($this->app_version) < 320){
                $param_style_box_w = 0;
                $param_style_box_h = 0;
            }else{
                $param_style_box_w = $style_box_w;
                $param_style_box_h = $style_box_h;
            }
            if($image->type==1){
                //图片
                $image_style_box = $this->create_image($image,$image_style_box,$image_make_picture,$multiple,$color_transparent,$param_style_box_w,$param_style_box_h);
                if(is_array($image_style_box) && isset($image_style_box['state'])){
                    return $image_style_box;
                }
            }else{
                //字体
                $image_style_box = (empty($this->app_version) || GeneralTool::compare_versions($this->app_version) < 312)
                || (!isset($image->font_svg) || empty((array)$image->font_svg)) ?
                    $this->create_font($image,$image_style_box,$style_box_w,$style_box_h,$multiple) :
                    $this->create_font_image($image,$image_style_box,$multiple,$color_transparent,$param_style_box_w,$param_style_box_h);
//                $image_style_box = $this->create_font($image,$image_style_box,$style_box_w,$style_box_h,$multiple);
                if(is_array($image_style_box) && isset($image_style_box['state'])){
                    return $image_style_box;
                }
            }
        }
        $image_make_picture->destory();
        return $image_style_box;
    }

    /**
     * 图片
     * @param $user_id
     * @param $image
     * @param $image_style_box
     * @param $image_make_picture
     * @param $multiple
     * @param $color_transparent
     * @return mixed
     * @throws ImageNotFoundException
     */
    private function create_image($image,$image_style_box,$image_make_picture,$multiple,$color_transparent,$style_box_w=0,$style_box_h=0){
        //$image_offset_x = $image->image_center_point_offset_x-$image->image_finnal_size_width/2;
        //$image_offset_y = $image->image_center_point_offset_y-$image->image_finnal_size_height/2;//偏移的位置
        $image_finnal_size_width = round($image->image_finnal_size_width*$multiple);
        $image_finnal_size_height = round($image->image_finnal_size_height*$multiple);
        //$image_offset_y = round($image_offset_y*$multiple);
        //$image_offset_x = round($image_offset_x*$multiple);
        $image_center_point_offset_x = $image->image_center_point_offset_x*$multiple;
        $image_center_point_offset_y = $image->image_center_point_offset_y*$multiple;
        if($image->image_type == 2){
            $source_pic_result = $this->source_pic_tool->getSourcePicAvailableBySourcePicIdAndProdTempId($image->creative_id,$this->product_temp_id,1);
            if($source_pic_result['state'] != 'M00000'){
                return $source_pic_result;
            }
            if(empty($source_pic_result['result']->thumbnail) || !is_file(public_path('images/').$source_pic_result['result']->thumbnail)){
                throw new ImageNotFoundException('地址为'.$source_pic_result['result']->thumbnail.',素材ID为'.$image->creative_id.',素材类型为'.$image->image_type.'的图片未找到');
            }
            $image->thumbnail = $source_pic_result['result']->thumbnail;
            $image->title = $source_pic_result['result']->name;
        }else{
            $image->original_image = ImgTool::getImgPathByImgUrl($image->original_image);
            if(empty($image->original_image) || !is_file(public_path('images/').$image->original_image)){
                throw new ImageNotFoundException('地址为'.$image->original_image.',素材ID为'.$image->creative_id.',素材类型为'.$image->image_type.'的原图片未找到');
            }
            $image->thumbnail = ImgTool::getImgPathByImgUrl($image->thumbnail);
            if(empty($image->thumbnail) || !is_file(public_path('images/').$image->thumbnail)){
                throw new ImageNotFoundException('地址为'.$image->thumbnail.',素材ID为'.$image->creative_id.',素材类型为'.$image->image_type.'的图片未找到');
            }
            //自定义素材
            $image->title = '自定义素材';
            $image->creative_id = date('YmdHis') . substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
            DB::table('user_creatives')->insert(array('creative_id'=>$image->creative_id,'user_id'=>$this->user_id,'original_image'=>$image->original_image,'thumbnail'=>$image->thumbnail,'created_at'=>time(),'updated_at'=>time()));
        }
        $creative_image = $image_make_picture->readImage(public_path('images/').$image->thumbnail);//是素材图片
        if($image->is_horizontal_filp == 1){
            $creative_image->flop();
        }
        if($image->is_vertical_filp == 1){
            $creative_image->flip();
        }
        $creative_image->resize($image_finnal_size_width,$image_finnal_size_height,'force');
        if(isset($image->mask_id) && $image->mask_id != 0){
            $image->mask_thumbnail = DB::table('masks')->where(['mask_id'=>$image->mask_id,'state'=>1])->value('thumbnail');
            if(empty($image->mask_thumbnail) || !is_file(public_path('images/').$image->mask_thumbnail)){
                throw new ImageNotFoundException('ID为'.$image->mask_id.'的遮罩未找到');
            }
            $creative_image = $this->create_mask($image,$creative_image,$multiple,$color_transparent,$style_box_w,$style_box_h);
        }
        $creative_image->rotateImage(rad2deg($image->image_angle),$color_transparent);
        $image_style_box->addWatermarkFromImage($creative_image,$image_center_point_offset_x-$creative_image->getImageWidth()/2+$style_box_w/2,
            $image_center_point_offset_y-$creative_image->getImageHeight()/2+$style_box_h/2);
        // $image_style_box->addWatermarkFromImage($creative_image,$image_offset_x-($image_offset_x+$creative_image->getImageWidth()/2-$image_center_point_offset_x),$image_offset_y -($image_offset_y +$creative_image->getImageHeight()/2-$image_center_point_offset_y));
        return $image_style_box;
    }

    /**
     * 使用svg绘制字体
     * @param $image
     * @param $image_style_box
     * @param $multiple
     * @param $color_transparent
     * @return array
     * @throws FontNotFoundException
     */
    public function create_font_image($image,$image_style_box,$multiple,$color_transparent,$style_box_w=0,$style_box_h=0){
        $font_offset_x = $image->font_center_point_offset_x*$multiple;
        $font_offset_y = $image->font_center_point_offset_y*$multiple;//偏移的位置
        $font_angle = rad2deg($image->font_angle);
        $font = DB::table('fonts')
            ->where([['font_id','=',$image->font_id]])
            ->select('font_path','font_name','font_type','font_image','state')
            ->first();
        if(empty($font) || !is_file(public_path('fonts/').$font->font_path)){
            throw new FontNotFoundException('地址为'.$image->font_id.'的字体未找到');
        }
        if($font->state == 2){
            return array('message'=>$font->font_name.'字体涉及版权问题,不能使用','result'=>(object)array(),'state'=>'M13003');
        }
        $image->font_name = $font->font_name;
        $image->font_image = $font->font_image;
        //生成svg
        $svg_path = $this->generate_svg($image->font_svg,$multiple);
        $image_png_path = $this->svgtopng($svg_path);
        if($image_png_path == false){
            throw new \Exception('svg字体生成png图片失败');
        }
        $svg_font_image = new Imagick(public_path(self::PREFIX_PATH.$image_png_path));
        $svg_font_image->rotateImage($font_angle,$color_transparent);
        $image_style_box->addWatermarkFromImage($svg_font_image,$font_offset_x-$svg_font_image->getImageWidth()/2+$style_box_w/2,$font_offset_y-$svg_font_image->getImageHeight()/2+$style_box_h/2);
        return $image_style_box;

    }

    /**
     * 字体
     * @param $image
     * @param $image_style_box
     * @param $style_box_w
     * @param $style_box_h
     * @param $multiple
     * @return mixed
     * @throws FontNotFoundException
     */
    private function create_font($image,$image_style_box,$style_box_w,$style_box_h,$multiple){
        $font_offset_x = $image->font_center_point_offset_x*$multiple;
        $font_offset_y = $image->font_center_point_offset_y*$multiple;//偏移的位置
        $font_angle = rad2deg($image->font_angle);
        $font_size =  $image->font_size*$multiple;
        //获取支持中文的字体  如果不支持 直接提示 默认字体为1
        $font = DB::table('fonts')
            ->where([['font_id','=',$image->font_id]])
            ->select('font_path','font_name','font_type','font_image','state')
            ->first();
        if(empty($font) || !is_file(public_path('fonts/').$font->font_path)){
            throw new FontNotFoundException('地址为'.$image->font_id.'的字体未找到');
        }
        if($font->state == 2){
            return array('message'=>$font->font_name.'字体涉及版权问题,不能使用','result'=>(object)array(),'state'=>'M13003');
        }
//            $font_array = DB::table('fonts')->where(['state'=>1])->whereIn('font_type', [1, 2])->pluck('font_id')->toArray();
//            $is_exist = in_array($image->font_id,$font_array);
        if(preg_match("/[\x7f-\xff]/", $image->text) && $font->font_type == 0){
            //不支持中文
            return array('message'=>$font->font_name.'字体不支持中文','result'=>(object)array(),'state'=>'M13004');
        }
        $image->font_name = $font->font_name;
        $image->font_image = $font->font_image;
        $image_style_box->addText($image->text,$font_offset_x-$style_box_w/2,$font_offset_y-$style_box_h/2,$font_angle,array('font'=>public_path('fonts/'.$font->font_path),'font_size'=>$font_size,'fill_color'=>$image->font_color,'font_alpha'=>$image->font_alpha));
        return $image_style_box;
    }

    /**
     * 绘制蒙版图片
     * @param $image
     * @param $creative_image
     * @param $multiple
     * @param $color_transparent
     * @return mixed
     */
    public function create_mask($image,$creative_image,$multiple,$color_transparent,$style_box_w=0,$style_box_h=0){
        // $color_transparent = new \ImagickPixel('transparent');
        $mask_center_point_offset_x = isset($image->mask_center_point_offset_x) ? ($image->mask_center_point_offset_x*$multiple) : 0;
        $mask_center_point_offset_y = isset($image->mask_center_point_offset_y) ? ($image->mask_center_point_offset_y*$multiple) : 0;
        $mask_finnal_size_width = isset($image->mask_finnal_size_width) ? round($image->mask_finnal_size_width*$multiple) : 0;//在ios上的素材大小
        $mask_finnal_size_height = isset($image->mask_finnal_size_height) ? round($image->mask_finnal_size_height*$multiple) : 0;
        $mask_bg = new Imagick();
        $mask_image = new Imagick(public_path('images/'.$image->mask_thumbnail));
        $mask_image->resize($mask_finnal_size_width,$mask_finnal_size_height,'force');
        $mask_bg = $mask_bg->newImage($creative_image->getImageWidth(),$creative_image->getImageHeight(),$color_transparent,'png');
        // $mask_bg->addWatermarkFromImage($mask_image,$mask_center_point_offset_x-($mask_center_point_offset_x+$mask_image->getImageWidth()/2-$mask_center_point_offset_x),$mask_center_point_offset_y-($mask_center_point_offset_y+$mask_image->getImageHeight()/2-$mask_center_point_offset_y));

        $mask_bg->addWatermarkFromImage($mask_image,$mask_center_point_offset_x-$mask_image->getImageWidth()/2+$creative_image->getImageWidth()/2,$mask_center_point_offset_y-$mask_image->getImageHeight()/2+$creative_image->getImageHeight()/2);
        $creative_image->getImagick()->setImageMatte(1);
        $creative_image->getImagick()->compositeImage($mask_bg->getImagick(), \Imagick::COMPOSITE_DSTIN, 0, 0);
        return $creative_image;
    }

    /**
     * 创建文件夹
     * @param $path
     */
    function mkFolder($path)
    {
        if(!is_readable($path))
        {
            is_file($path) or mkdir($path,0777);
        }
    }

    /**
     * 十六进制 转 RGB
     */
    function hex2rgb($hexColor) {
        $color = str_replace('#', '', $hexColor);
        if (strlen($color) > 3) {
            $rgb = array(
                '0' => hexdec(substr($color, 0, 2)),
                '1' => hexdec(substr($color, 2, 2)),
                '2' => hexdec(substr($color, 4, 2)),
                '3' => 255
            );
        } else {
            $color = $hexColor;
            $r = substr($color, 0, 1) . substr($color, 0, 1);
            $g = substr($color, 1, 1) . substr($color, 1, 1);
            $b = substr($color, 2, 1) . substr($color, 2, 1);
            $rgb = array(
                '0' => hexdec($r),
                '1' => hexdec($g),
                '2' => hexdec($b),
                '3' => 255
            );
        }
        return $rgb;
    }

    /**
     * 生成svg文件
     * @param $svg_param
     * @param int $scale
     * @return string
     * @throws \Exception
     */
    private function generate_svg($svg_param,$scale=1){
        $svg = new SvgFont();
        $arr = $svg->get_array_to_use($svg_param,$scale);
        $svg->set_font_family($arr['font_family']);
        $svg->set_font_size($arr['font_size']);
        $svg->set_font_newline($arr['newline']);
        $svg->set_scale($arr['scale']);
        //$svg->setFontColor($arr['fill']);
        $svg->set_font_fill($arr['fill']);
        $svg->addText($arr['text']);

        $svg->addAttribute("width", ($svg->get_text_width() + $svg->get_x_begin()) ."px");
        $svg->addAttribute("height", $svg->get_text_height() . "px");
        $svg_folder_path =  'svg' . DIRECTORY_SEPARATOR . date('Ym');
        @$this->mkFolder(public_path('images/' .$svg_folder_path));
        $svg_path = $svg_folder_path . '/' . md5(date('ymdhis').rand(1, 1000)) . ".svg";
        //echo $svg->asXML('');
        $result = $svg->asXML(public_path('images' . DIRECTORY_SEPARATOR .  $svg_path));
        return $svg_path;
    }

    /**
     * svg生成png图片
     * @param $svg_path
     * @return bool|string
     */
    public function svgtopng($svg_path){
        //生成svg文件名
        if(!file_exists(public_path(self::PREFIX_PATH.$svg_path))){
            return false;
        }

        $file_path="svg/".date('Ym');
        $folder_path=public_path(). self::PREFIX_PATH.$file_path;
        @$this->mkFolder($folder_path);
        //生成图片名
        $svg_png_name = md5(date('ymdhis').rand(1, 1000)) . ".png";
        $svg_png_absolute_path=$folder_path.'/'.$svg_png_name;

        $z = new \XMLReader;
        $z->open(public_path(self::PREFIX_PATH.$svg_path));
        while ($z->read()) {
            $name = $z->name;
            if ($z->nodeType == \XMLReader::ELEMENT) {
                if($name == 'svg'){
                    $width = $z->getAttribute('width');
                    $width=str_replace('px','',$width);
                    $height = $z->getAttribute('height');
                    $height=str_replace('px','',$height);
                    break;
                }
            }
        }
        Log::info($svg_path);
        Log::info($file_path.'/'.$svg_png_name);

        $output = shell_exec('/usr/local/imagemagick/bin/convert -density 288 -background none -resize '.$width.'x'.$height.' '
            .public_path().self::PREFIX_PATH.$svg_path.' '.$svg_png_absolute_path.' &&  echo "success"');
        // $output = shell_exec('convert -density 288 -background none -resize '.$width.'x'.$height.' '
        //     .public_path().self::PREFIX_PATH.$svg_path.' '.$svg_png_absolute_path.' &&  echo "success"');
        // $outdataput = array();
        // $code = '';
        // $cmd = 'convert -density 288 -background none -resize '.$width.'x'.$height.' '
        //     .public_path().self::PREFIX_PATH.$svg_path.' '.$svg_png_absolute_path;
        // Log::info($cmd);
        // $output = exec($cmd,$outdataput,$code);
        // Log::info($outdataput);
        // Log::info($code);
        //dd($file_path.'/'.$svg_png_name . ' | ' . $svg_path);

        // $im = new \Imagick();
        // // $im->->setImageResolution(288, 288);
        // //$im->setResolution(288,288);
        // $im->setBackgroundColor(new \ImagickPixel('transparent'));
        // $im->readImage(public_path().self::PREFIX_PATH.$svg_path);
        // $im->setImageUnits(\Imagick::RESOLUTION_PIXELSPERINCH);
        // $im->setImageFormat("png");
        // $im->writeImage($svg_png_absolute_path);
        // $im->clear();
        // $im->destroy();
        // Log::info('测试是否变粗');
        // $im = new \Imagick();
        // $im->setResolution(288,288);
        // $im->readImage($svg_png_absolute_path);
        // $im->writeImage($svg_png_absolute_path);
        // $im->clear();
        // $im->destroy();

        // return file_exists($svg_png_absolute_path) ? $file_path.'/'.$svg_png_name : false;
        return !empty($output) ? $file_path.'/'.$svg_png_name : false;
    }
}
